package com.flowable.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.common.util.Excel.ExcelUtil;
import com.flowable.Excel.SysExpressionExcel;
import com.flowable.domain.dto.SysExpression;
import com.flowable.service.ISysExpressionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 流程达式Controller
 *
 * @author ruoyi
 * @date 2022-12-12
 */
@RestController
@RequestMapping("/flowable/expression")
public class SysExpressionController {
    @Autowired
    private ISysExpressionService sysExpressionService;

    /**
     * 查询流程达式列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询流程达式列表接口")
    public ResponseEntity list(Page pageDto, SysExpression sysExpression) {
        return sysExpressionService.selectSysExpressionList(pageDto, sysExpression);
    }

    /**
     * 获取流程达式详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取流程达式详细信息")
    public ResponseEntity getInfo(@PathVariable("id") Long id) {
        return sysExpressionService.selectSysExpressionById(id);
    }

    /**
     * 新增流程达式
     */

    @PostMapping("/save")
    @ApiOperation(value = " 修改流程达式接口")
    public ResponseEntity save(@RequestBody SysExpression sysExpression) {
        return sysExpressionService.save(sysExpression);
    }


    /**
     * 删除流程达式
     */
    @DeleteMapping("/del")
    @ApiOperation(value = " 删除流程达式接口")
    public ResponseEntity remove(@RequestBody List<Long> ids) {
        return sysExpressionService.deleteSysExpressionByIds(ids.toArray(new Long[ids.size()]));
    }

    @ApiOperation("流程达式导出")
    @PostMapping("/export")
    public void export(HttpServletResponse response) {
        ExcelUtil.export(response, "流程达式数据", "流程表达式表", sysExpressionService.ExportList(), SysExpressionExcel.class);
    }


}
